#ifndef __UART_H
#define __UART_H

#include "gd32f30x.h"

#define USART1_RX_NUM							4096+1
#define USART1_TX_NUM							100
#define MAX_USART1_RX_TIMEOUT			80

#define USART1_TX_PORT	GPIOA
#define USART1_TX_PIN		GPIO_PIN_2
#define USART1_RX_PORT	GPIOA
#define USART1_RX_PIN		GPIO_PIN_3

#define USART2_TX_PORT	GPIOC
#define USART2_TX_PIN		GPIO_PIN_10
#define USART2_RX_PORT	GPIOC
#define USART2_RX_PIN		GPIO_PIN_11

#define ENABLE_USART1_DMA0
#define ENABLE_USART2_DMA0

/* 使结构体按2字节方式对齐 */
#pragma pack(2)
typedef struct
{
  uint8_t   wait_cnt; 			// 读传感器等待计时器, 发送时收到新数据时清零, 单位10ms
	uint8_t   fix_tx_delay;		// 周期性发送数据延时
	uint8_t   time_out_flag;	// 通信超时标记位
	uint8_t   time_out_cnt;		// 通信超时计次
	uint16_t 	rx_num; 				// 接收缓冲区计数器
	uint8_t 	rx_finish_cnt; 	// 接收完成计时
	uint8_t 	rx_finish_flag; // 接收完成标记
}Usart_TypeDef;

/* Public functions ----------------------------------------------------------*/
void Usart_Init(uint32_t usart_periph);
void Usart_TxByte(uint32_t usart_periph, uint8_t data);
void Usart_Tx_Buff(uint32_t usart_periph, uint8_t* data, uint16_t len);
void Uart_DMA_Config(uint32_t usart_periph);



/* Exported variables --------------------------------------------------------*/
extern Usart_TypeDef		usart2_var;			// 传感器头通信数据
extern uint8_t 	USART1_Rx_BUF[];
extern uint8_t	USART1_Tx_BUF[];


#endif	/* __UART_H */

